﻿using FarmSmartSleep.Common.Domain.PM.select;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.ProductionManagement.MotherHybridizationCommands
{
    public class HybridizationTypeSearchHander : IRequestHandler<HybridizationTypeSearchCommand, ResultT<HybridizationType>>
    {
        private readonly ILogger<HybridizationTypeSearchHander> logger;
        private readonly IBaseRepository<HybridizationType> baseRepository;

        public HybridizationTypeSearchHander(ILogger<HybridizationTypeSearchHander> logger, IBaseRepository<HybridizationType> baseRepository)
        {
            this.logger = logger;
            this.baseRepository = baseRepository;
        }
        /// <summary>
        /// 获取种母配种方式
        /// </summary>
        /// <param name="request">获取种母配种方式请求对象</param>
        /// <param name="cancellationToken"></param>
        /// <returns>获取种母配种方式信息集合</returns>
        public async Task<ResultT<HybridizationType>> Handle(HybridizationTypeSearchCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new ResultT<HybridizationType>();
                result.Data = baseRepository.GetAll().ToList();
                logger.LogInformation("获取配种类型方法调用成功");
                return result;
            }
            catch (Exception ex )
            {
                logger.LogError("获取配种类型方法调用出错" + ex);
                throw;
            }
        }
    }
}
